package system.fan.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import system.fan.mapper.CustomerMapper;
import system.fan.pojo.Customer;

import java.util.List;
@Service
public class CustomerServiceImpl implements CustomerService{
    @Autowired
    private CustomerMapper customerMapper;
    @Override
    public void insertCustomer(Customer customer) {
        customerMapper.insertCustomer(customer);
    }

    @Override
    public void updateCustomer(Customer customer) {
        if(customer.getId()!=null){
            customerMapper.updateCustomer(customer);
        }else {
//            TODO 如果id为空,需要提醒用户!
        }
    }

    @Override
    public void deleteCustomerBYID(Integer id) {
        if(id !=null){
            customerMapper.deleteCustomerBYID(id);
        }else {
//            TODO 如果id为空,需要提醒用户!
        }
    }

    @Override
    public Customer selectCustomerBYID(Integer id) {
        if(id !=null){
            Customer customer=customerMapper.selectCustomerBYID(id);
            return customer;
        }else {
//            TODO 如果id为空,需要提醒用户!
            return null;
        }
    }

    @Override
    public List<Customer> selectAll() {
        List<Customer> customerList=customerMapper.selectAll();
        return customerList;
    }

    @Override
    public PageInfo<Customer> selectAllByPage(Integer page, Integer limit) {
        PageHelper.startPage(page,limit);
        List<Customer> customerList=customerMapper.selectAll();
        PageInfo<Customer> customerPageInfo=new PageInfo<>(customerList);
        return customerPageInfo;
    }

    @Override
    public void deleteCustomerByIDs(int[] ids) {
        customerMapper.deleteCustomerByIDs(ids);
    }


}
